<script setup>
	import {
		onLaunch,
		onShow,
		onHide
	} from '@dcloudio/uni-app'

	import userstore from './store/user';

	import {
		ref,
		onMounted
	} from 'vue';

	const {
		update
	} = userstore();


	onLaunch(() => {
		console.log('应用启动')
		update((islogin) => {
			console.log(('用户登录状态', islogin));
		})
	})


	// 定义一个变量来存储当前的主题，默认为日间主题
	const currentTheme = ref('day');

	// 初始化主题的方法
	const initTheme = () => {
		uni.getStorage({
			key: 'theme',
			success: (res) => {
				currentTheme.value = res.data;
				applyTheme();
			},
			fail: () => {
				// 如果没有存储的主题，则使用默认值
				currentTheme.value = 'day';
				applyTheme();
			}
		});
	};

	// 应用主题的方法
	const applyTheme = () => {
		document.body.className = currentTheme.value;
	};

	// 切换主题的方法
	const toggleTheme = () => {
		currentTheme.value = currentTheme.value === 'day' ? 'night' : 'day';
		setTheme();
	};

	// 设置主题的方法
	const setTheme = () => {
		const theme = currentTheme.value;
		uni.setStorage({
			key: 'theme',
			data: theme,
			success: () => {
				console.log('Theme saved successfully');
				applyTheme();
			}
		});
	};

	// 页面加载时初始化主题
	onMounted(() => {
		initTheme();
	});
</script>

<style>
	/*每个页面公共css */
	body.day {
		background-color: #ffffff;
		color: #000000;
	}

	body.night {
		background-color: #ffffea;
	}

	img {
		max-width: 100%;
		height: auto;
	}
</style>